<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

$this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
$this->output->set_header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
$this->output->set_header("Cache-Control: no-cache, must-revalidate");
header('Cache-Control: post-check=0, pre-check=0', false );
$this->output->set_header("Pragma: no-cache");

//--- BEGIN HEADER
echo	"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
echo	"<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">";
echo		"<head>";
echo			"<title>STUDY</title>";
echo			"<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"/>";
echo			"<link rel=\"stylesheet\" type=\"text/css\" href=\"".MEDIA."admin_lte/analytics/main.css\"/>";
?>
	<script type="text/javascript" src="<?=MEDIA?>js/jquery.js"></script>
<?
echo		"</head>";
echo		"<body style=\"padding: 10px; background-color: #FFFFFF;\">";
?>

 <script src="<?=MEDIA?>admin_lte/analytics/bundle.js"></script>

<script>
(function(w,d,s,g,js,fs){
  g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f);}};
  js=d.createElement(s);fs=d.getElementsByTagName(s)[0];
  js.src='https://apis.google.com/js/platform.js';
  fs.parentNode.insertBefore(js,fs);js.onload=function(){g.load('analytics');};
}(window,document,'script'));
</script>

<div id="embed-api-auth-container"></div>
<div id="chart-container"></div>
<div id="view-selector-container" class="ViewSelector"></div>

<script>

gapi.analytics.ready(function() {

  /**
   * Authorize the user immediately if the user has already granted access.
   * If no access has been created, render an authorize button inside the
   * element with the ID "embed-api-auth-container".
   */
  gapi.analytics.auth.authorize({
    container: 'embed-api-auth-container',
    clientid: '493379758758-iqvdkt1dnms0vio6f58ogp37agh8d5dt.apps.googleusercontent.com',
  });


  /**
   * Create a new ViewSelector instance to be rendered inside of an
   * element with the id "view-selector-container".
   */
  var viewSelector = new gapi.analytics.ViewSelector({
    container: 'view-selector-container'
  });

  // Render the view selector to the page.
  viewSelector.execute();


  /**
   * Create a new DataChart instance with the given query parameters
   * and Google chart options. It will be rendered inside an element
   * with the id "chart-container".
   */
  var dataChart = new gapi.analytics.googleCharts.DataChart({
    query: {
      metrics: 'ga:sessions',
      dimensions: 'ga:date',
      'start-date': '30daysAgo',
      'end-date': 'yesterday'
    },
    chart: {
      container: 'chart-container',
      type: 'LINE',
      options: {
        width: '100%'
      }
    }
  });


  /**
   * Render the dataChart on the page whenever a new view is selected.
   */
  viewSelector.on('change', function(ids) {
    dataChart.set({query: {ids: ids}}).execute();
  });

});
</script>

	</body>
</html>